package ptij.vocoder.baseModel.common;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// Join
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class Join extends TypedAtomicActor {

    public Join(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        input1 = new TypedIOPort(this, "input1", true, false);
        input1.setTypeEquals(BaseType.OBJECT);

        input2 = new TypedIOPort(this, "input2", true, false);
        input2.setTypeEquals(BaseType.OBJECT);

        output = new TypedIOPort(this, "output", false, true);
        output.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort input1;
    public TypedIOPort input2;

    // Output Ports
    public TypedIOPort output;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) input1.get(0);
        Short [] frame1 = (Short []) obj.getValue();
        
        obj = (ObjectToken) input2.get(0);
        Short [] frame2 = (Short []) obj.getValue();
        
        Short [] newframe = new Short[frame1.length + frame2.length];
        int pos = 0;
        for(int i = 0;i < frame1.length;i++) {
            newframe[pos] = frame1[i];
            pos++;
        }
        for(int i = 0;i < frame2.length;i++) {
            newframe[pos] = frame2[i];
            pos++;
        }
        output.broadcast(new ObjectToken(newframe));
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////
   

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

}
